<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>患者注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', sans-serif;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
        }

        .register-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 15px 30px rgba(0,0,0,0.1);
            padding: 40px 60px;
            width: 100%;
            max-width: 800px;
        }

        .page-title {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }

        .form-group {
            display: flex;
            margin-bottom: 20px;
        }

        .form-label {
            width: 80px;
            color: #34495e;
            font-size: 0.9em;
            margin-right: 15px;
            margin-top: 12px;
            text-align: right;
        }

        .form-input-container {
            flex: 1;
        }

        .form-input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            font-size: 1em;
            transition: border-color 0.3s;
        }

        .form-input:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
        }

        .row {
            display: flex;
            gap: 30px;
        }

        .half-col {
            flex: 1;
        }

        .gender-group {
            display: flex;
            gap: 20px;
            margin-top: 12px;
        }

        .gender-label {
            color: #34495e;
            font-size: 0.9em;
            margin-left: 5px;
        }

        .gender-radio {
            accent-color: #3498db;
        }

        .submit-btn {
            width: 100%;
            padding: 14px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1em;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.3s;
        }

        .submit-btn:hover {
            background: #2980b9;
        }

        .footer-text {
            text-align: center;
            color: #7f8c8d;
            margin-top: 20px;
        }

        .footer-text a {
            color: #3498db;
            text-decoration: none;
        }

        /* 新增提醒样式 */
        .message-box {
            margin: 20px 0;
            padding: 12px 18px;
            border-radius: 8px;
            font-size: 0.9em;
            line-height: 1.4;
            display: none; /* 默认隐藏 */
        }

        .message-box.show {
            display: block; /* 显示时激活 */
        }

        /* 成功提醒样式 */
        .message-box.success {
            background-color: #e0f3d8;
            color: #2e7d32;
            border: 1px solid #c8e6c9;
        }

        /* 错误提醒样式 */
        .message-box.error {
            background-color: #fcebeb;
            color: #b71c1c;
            border: 1px solid #ef9a9a;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .register-container {
                padding: 30px 20px;
            }

            .row {
                flex-direction: column;
                gap: 20px;
            }

            .form-label {
                width: 70px;
                margin-right: 10px;
            }
        }
    </style>
</head>
<body>
<div class="register-container">
    <h2 class="page-title">患者注册</h2>
    <form th:action="@{/insertPatient}" method="post">
        <div class="row">
            <div class="half-col">
                <div class="form-group">
                    <label class="form-label" for="name">姓名</label>
                    <div class="form-input-container">
                        <input type="text" class="form-input" id="name" name="name" placeholder="请输入姓名" required>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" >性别</label>
                    <div class="form-input-container">
                        <div class="gender-group">
                            <div>
                                <input type="radio" id="male" name="gender" value="男" class="gender-radio" required>
                                <label class="gender-label" for="male">男</label>
                            </div>
                            <div>
                                <input type="radio" id="female" name="gender" value="女" class="gender-radio" required>
                                <label class="gender-label" for="female">女</label>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="phone">联系电话</label>
                    <div class="form-input-container">
                        <input type="tel" class="form-input" id="phone" name="phone" placeholder="请输入手机号" pattern="[0-9]{11}" required>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="account">账号</label>
                    <div class="form-input-container">
                        <input type="text" class="form-input" id="account" name="account" placeholder="请设置登录账号" required>
                    </div>
                </div>
            </div>

            <div class="half-col">
                <div class="form-group">
                    <label class="form-label" for="age">年龄</label>
                    <div class="form-input-container">
                        <input type="number" class="form-input" id="age" name="age" placeholder="自动计算" readonly>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="birth_date">出生日期</label>
                    <div class="form-input-container">
                        <input type="date" class="form-input" id="birth_date" name="birth_date" onchange="calculateAge()">
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="id_card">身份证号</label>
                    <div class="form-input-container">
                        <input type="text" class="form-input" id="id_card" name="id_card" placeholder="请输入18位身份证号" pattern="[0-9Xx]{18}" required>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="pwd">密码</label>
                    <div class="form-input-container">
                        <input type="password" class="form-input" id="pwd" name="pwd" placeholder="请设置登录密码" minlength="6" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="form-label" for="address">联系地址</label>
            <div class="form-input-container">
                <input type="text" class="form-input" id="address" name="address" placeholder="请输入联系地址">
            </div>
        </div>

        <input type="hidden" name="role" value="PATIENT">

        <button type="submit" class="submit-btn">立即注册</button>

        <div class="footer-text">
            已有账号？<a th:href="@{/login}">点击登录</a>
        </div>
        <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示：</div>
            <p th:text="${message}"></p>
        </div>
    </form>
</div>
<script>
    // 根据出生日期自动计算年龄
    function calculateAge() {
        const birthDateInput = document.getElementById('birth_date');
        const ageInput = document.getElementById('age');

        if (birthDateInput.value) {
            const birthDate = new Date(birthDateInput.value);
            const today = new Date();

            let age = today.getFullYear() - birthDate.getFullYear();
            const monthDiff = today.getMonth() - birthDate.getMonth();

            if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
                age--;
            }

            ageInput.value = age;
        } else {
            ageInput.value = '';
        }
    }
</script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script>
    $(".message .close").on('click', function () {
        $(this).closest(".message").transition("fade");
    })
</script>
</body>
</html>